#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <gio/gio.h>
#include <glib.h>
#include <QMainWindow>
#include <QVBoxLayout>
#include <QPushButton>
#include <QComboBox>
#include <QTranslator>
#include <QMap>
#include <QLabel>
#include "powertray.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    void loadLanguage(const QString &language);
    void retranslateUi();
    void onExitRequired();
private:
    Ui::MainWindow *ui;
    GSettings *m_settings;
    GSettings *screen_settings;
    GSettings *process_settings;
    QTranslator *appTranslator;
    class SettingsWidget *settingsWidget;
    QLineEdit *searchBox;
    QMenu *languageMenu;
    QAction *chineseAction;
    QAction *englishAction;
    PowerTray *powerTray;
    bool trayIconVisible = false;
  //  QTranslator *qtTranslator;
protected:
    void closeEvent(QCloseEvent *event) override;
private slots:
    void onShowTrayIcon(bool checked);

};

class SettingsWidget : public QWidget
{
    Q_OBJECT

public:
    SettingsWidget(QWidget *parent = nullptr, GSettings *settings = nullptr);
    void retranslateUi();
    QPushButton* getSlideButton(const QString& key);
private slots:
    void onSettingChanged(const QString &key);
    void updateSlideButton(const QString &key);
    void updateComboBox(const QString &key);
protected:
    void changeEvent(QEvent *event) override;
private:
    void addSetItem(QVBoxLayout *layout, const QString &text, const QString &gsettings_key, GSettings *settings);
    void addSetCombo(QVBoxLayout *layout, const QString &text, const QStringList &items, const QString &gsettings_key,bool isIntType);
    void addSetdoubleCombo(QVBoxLayout *layout);
    int textToInt(const QString &text);
    QString textToValidEnum(const QString &text);
    QString enumToText(const QString &text);
    static void settingsChangedCallBack(GSettings *settings, gchar *key, gpointer user_data);
    GSettings *m_settings;
    GSettings *screen_settings;
    GSettings *process_settings;
//记录键值对应的组件
    QMap<QString,QPushButton*>m_slideButtons;
    QMap<QString,QComboBox*>m_comboBoxes;
   //记录组件的描述
    QMap<QString, QLabel*> m_labels;
    QMap<QString, QComboBox*> m_combos;

};
#endif // MAINWINDOW_H
